<template>
  <div>
    <div class="gva-form-box">
      <el-form :model="formData" ref="elFormRef" label-position="right" :rules="rule" label-width="80px">
        <el-form-item label="用户标识:" prop="userId">
          <el-input v-model="formData.userId" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="订单ID:" prop="orderId">
          <el-input v-model="formData.orderId" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="平台类型：1、IOS,2、android，3、微信:" prop="platId">
          <el-input v-model.number="formData.platId" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="小程序Id:" prop="appId">
          <el-input v-model="formData.appId" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="app版本名字:" prop="version">
          <el-input v-model="formData.version" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="渠道id:" prop="channelId">
          <el-input v-model="formData.channelId" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="推广id:" prop="referralId">
          <el-input v-model="formData.referralId" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="客户端ip:" prop="clientIp">
          <el-input v-model="formData.clientIp" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="设备号:" prop="deviceId">
          <el-input v-model="formData.deviceId" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="产品标识:" prop="productId">
          <el-input v-model="formData.productId" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="产品名字:" prop="productName">
          <el-input v-model="formData.productName" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="产品类型：1、月卡,2、平台币:" prop="productType">
          <el-input v-model.number="formData.productType" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="金额（分）:" prop="productCost">
          <el-input v-model.number="formData.productCost" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="月卡为天数，看点:" prop="productAmount">
          <el-input v-model.number="formData.productAmount" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="赠送金额:" prop="productGive">
          <el-input v-model.number="formData.productGive" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="短剧ID:" prop="movieId">
          <el-input v-model.number="formData.movieId" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="短剧聚集id:" prop="episodeId">
          <el-input v-model.number="formData.episodeId" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="阅读序号:" prop="seq">
          <el-input v-model.number="formData.seq" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="支付类型:applepay(1) 微信(2) 支付宝(3):" prop="payType">
          <el-input v-model.number="formData.payType" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="支付状态:1、未支付，2、已支付:" prop="payStatus">
          <el-input v-model.number="formData.payStatus" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="微信支付类型：0 默认 ,1虚拟支付:" prop="payTypeVirtualWechat">
          <el-input v-model.number="formData.payTypeVirtualWechat" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="路径:" prop="trace">
          <el-input v-model="formData.trace" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="订单ID:" prop="thirdOrderId">
          <el-input v-model="formData.thirdOrderId" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="创建时间:" prop="createTime">
          <el-date-picker v-model="formData.createTime" type="date" placeholder="选择日期" :clearable="true"></el-date-picker>
       </el-form-item>
        <el-form-item label="更新时间:" prop="updateTime">
          <el-date-picker v-model="formData.updateTime" type="date" placeholder="选择日期" :clearable="true"></el-date-picker>
       </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="save">保存</el-button>
          <el-button type="primary" @click="back">返回</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import {
  createTRecharge,
  updateTRecharge,
  findTRecharge
} from '@/api/tRecharge'

defineOptions({
    name: 'TRechargeForm'
})

// 自动获取字典
import { getDictFunc } from '@/utils/format'
import { useRoute, useRouter } from "vue-router"
import { ElMessage } from 'element-plus'
import { ref, reactive } from 'vue'

const route = useRoute()
const router = useRouter()

const type = ref('')
const formData = ref({
            userId: '',
            orderId: '',
            platId: 0,
            appId: '',
            version: '',
            channelId: '',
            referralId: '',
            clientIp: '',
            deviceId: '',
            productId: '',
            productName: '',
            productType: 0,
            productCost: 0,
            productAmount: 0,
            productGive: 0,
            movieId: 0,
            episodeId: 0,
            seq: 0,
            payType: 0,
            payStatus: 0,
            payTypeVirtualWechat: 0,
            trace: '',
            thirdOrderId: '',
            createTime: new Date(),
            updateTime: new Date(),
        })
// 验证规则
const rule = reactive({
})

const elFormRef = ref()

// 初始化方法
const init = async () => {
 // 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
    if (route.query.id) {
      const res = await findTRecharge({ ID: route.query.id })
      if (res.code === 0) {
        formData.value = res.data.retRecharge
        type.value = 'update'
      }
    } else {
      type.value = 'create'
    }
}

init()
// 保存按钮
const save = async() => {
      elFormRef.value?.validate( async (valid) => {
         if (!valid) return
            let res
           switch (type.value) {
             case 'create':
               res = await createTRecharge(formData.value)
               break
             case 'update':
               res = await updateTRecharge(formData.value)
               break
             default:
               res = await createTRecharge(formData.value)
               break
           }
           if (res.code === 0) {
             ElMessage({
               type: 'success',
               message: '创建/更改成功'
             })
           }
       })
}

// 返回按钮
const back = () => {
    router.go(-1)
}

</script>

<style>
</style>
